package com.nbjtjc.safe.mapper.sys;

import com.nbjtjc.safe.model.sys.SysFile;
import com.nbjtjc.util.MyMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SysFileMapper extends MyMapper<SysFile> {

    @Select("select * from sys_file where f_id=#{fileId}")
    SysFile findById(@Param("fileId") int fileId);

    @Select("select * from sys_file where file_id=#{fileId} and version<#{vers} order by version desc")
    List<SysFile> findByFileId(@Param("fileId") int fileId,@Param("vers") int version);

    @Select("select * from sys_file where content_id=#{contentId} and content_type=#{contentType}" +
            " ORDER BY f_id DESC limit 0,1")
    SysFile findUserHeadFile(@Param("contentId") int contentId,@Param("contentType") int contentType);

    @Select("<script>"+
            "select * from sys_file " +
            "where content_type =#{idType} and content_id in" +
            " <foreach item='listId' index='index' collection='listIds'  open='(' separator=',' close=')'> " +
            "#{listId}" +
            " </foreach> "
            + "</script>")
    List<SysFile> findByContentIds(@Param("listIds") List<Integer> listIds,@Param("idType") Integer contentType);

    @Select("<script>"+
            "select * from sys_file " +
            "where content_type in   " +
            " <foreach item='idType' index='index' collection='idTypes'  open='(' separator=',' close=')'> " +
            "#{idType}" +
            " </foreach> "+
            "and content_id in" +
            " <foreach item='listId' index='index' collection='listIds'  open='(' separator=',' close=')'> " +
            "#{listId}" +
            " </foreach> "
            + "</script>")
    List<SysFile> findByContentIdsAndContentTypes(@Param("listIds") List<Integer> listIds,@Param("idTypes") List<Integer> contentTypes);
    @Select("<script>"+
            "select * from sys_file " +
            "where  content_id in" +
            " <foreach item='listId' index='index' collection='listIds'  open='(' separator=',' close=')'> " +
            "#{listId}" +
            " </foreach> "
            + "</script>")
    List<SysFile> findByContentIdsAllType(@Param("listIds") List<Integer> listIds);


    @Select("select * from sys_file where file_key=#{fileKey}")
    SysFile findFileByFileKey(@Param("fileKey") String fileKey);



    List<SysFile> search(@Param("sf") SysFile sysFile);

}